using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameFrameworkLibraly;
using GameFrameworkLibraly.BaseObjects;
using GameFrameworkLibraly.Helpers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameFramework
{
    internal class BoxObject:SpriteObject
    {
        private readonly float _moveSpeed;
        private readonly float _rotateSpeed;

        internal BoxObject(MyGame game, Texture2D texture) : base(game, Vector2.Zero, texture)
        {
            Game = game;

            PositionX = GameHelper.RandomNext(0, Game.Window.ClientBounds.Width);
            PositionY = GameHelper.RandomNext(0, Game.Window.ClientBounds.Height);


            OriginX = texture.Width / 2.0f;
            OriginY = texture.Height / 2.0f;

            SpriteColor = new Color(GameHelper.RandomNext(0, 256), GameHelper.RandomNext(0, 256), GameHelper.RandomNext(0, 256));

            _moveSpeed = GameHelper.RandomNext(2.0f) + 1;
            _rotateSpeed = GameHelper.RandomNext(-5.0f, 5.0f);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            PositionY += _moveSpeed;

            if (BoundingBox.Top > Game.Window.ClientBounds.Bottom)
                PositionY = -SpriteTexture.Height;

            Angle += MathHelper.ToRadians(_rotateSpeed);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            Rectangle boundingBox = BoundingBox;
            spriteBatch.Draw(SpriteTexture, new Rectangle(boundingBox.Left, BoundingBox.Top,3,3), Color.White);
            spriteBatch.Draw(SpriteTexture, new Rectangle(boundingBox.Left, BoundingBox.Bottom,3,3), Color.White);
            spriteBatch.Draw(SpriteTexture, new Rectangle(boundingBox.Right, BoundingBox.Top,3,3), Color.White);
            spriteBatch.Draw(SpriteTexture, new Rectangle(boundingBox.Right, BoundingBox.Bottom,3,3), Color.White);
        }
    }
}
